import Cookies from 'js-cookie'

const TokenKey = 'Turbo-Token'
const UserIDKey = 'Turbo-User-ID'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function setUserId(user_id) {
  return Cookies.set(UserIDKey, user_id)
}

export function getUserId() {
  return Cookies.get(UserIDKey)
}

export function setPageColumns(pageName, columns) {
  if (localStorage.getItem(pageName)) {
    localStorage.removeItem(pageName)
  }
  localStorage.setItem(pageName, JSON.stringify(columns))
}

export function getPageColumns(pageName) {
  const columns = localStorage.getItem(pageName)
  if (columns) {
    return JSON.parse(columns)
  }
  return []
}

export function getLocalBoolData(key) {
  const value = localStorage.getItem(key)
  if (value === 'true') {
    return true
  }
  return false
}

export function getCookieData(key) {
  const value = localStorage.getItem(key)
  return value
}

export function setCookieData(key, data) {
  if (localStorage.getItem(key)) {
    localStorage.removeItem(key)
  }
  return localStorage.setItem(key, data)
}
